package wordit.impl.letterCells;

import wordit.Game;
import wordit.Letter;
import wordit.ea.Genome;
import wordit.ea.GenomeFactory;

public class LetterCellGenomeFactory implements GenomeFactory {

	private final Game game;

	public LetterCellGenomeFactory(Game game) {
		this.game = game;
	}
	
	@Override
	public Genome createRandomGenome() {

		LetterCellGenome genome = new LetterCellGenome(game.getNumOfRows(), game.getNumOfColumns());
		int numOfCells = game.getNumOfColumns() * game.getNumOfRows();
		
		for (Letter l : game.getLetters()) {
			int location;
			do {
				location = (int) (Math.random() * numOfCells);
			} while (genome.getLetterAt(location)!=null);
			
			genome.addLetterCell(new LetterCell (l, location));
		}
		
		return genome;
	}
}
